package com.cn.lyl.servlet.lawyer;

import com.alibaba.fastjson.JSONObject;
import com.cn.lyl.model.LawyerModel;
import com.cn.lyl.model.LawyerRoleModel;
import com.cn.lyl.service.LawyerRoleService;
import com.cn.lyl.service.LawyerService;
import com.cn.lyl.service.UserService;
import com.cn.lyl.service.impl.LawyerRoleServiceImpl;
import com.cn.lyl.service.impl.LawyerServiceImpl;
import com.cn.lyl.service.impl.UserServiceImpl;
import com.cn.lyl.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/back/lawyer/add")
public class AddLawyerServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        List<LawyerRoleModel> lawyerRoleModelList = new ArrayList<>();
        LawyerRoleService lawyerRoleService = new LawyerRoleServiceImpl();
        lawyerRoleModelList=lawyerRoleService.findAll();
        String lawyerName = req.getParameter("lawyername");
        String head = (req.getParameter("head_pic"));
        String intro = req.getParameter("intro");
        String role = req.getParameter("role");
        LawyerModel lawyerModel = new LawyerModel();
        lawyerModel.setLawyerName(lawyerName);
        lawyerModel.setDependenceObj(role);
        lawyerModel.setHead(head);
        lawyerModel.setLawyerIntro(intro);
        LawyerService lawyerService = new LawyerServiceImpl();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",lawyerService.addLawyer(lawyerModel));
        jsonObject.put("roles",lawyerRoleModelList);
        resp.getWriter().print(jsonObject);
    }
}
